/*
  学习目标：卸载阶段
*/

import React, { Component } from 'react';

export default class App extends Component {
  state = {
    isShow: true,
  };

  render() {
    const { isShow } = this.state;
    return (
      <div>
        <button
          onClick={() => {
            this.setState({ isShow: !isShow });
          }}
        >
          点我更新isSHow
        </button>

        {isShow && <Child />}
      </div>
    );
  }
}

let timerId;

class Child extends React.Component {
  componentDidMount() {
    timerId = setInterval(() => {
      console.log('131  ----->  ', 131);
    }, 500);
  }

  render() {
    return <div>Child</div>;
  }

  // 卸载前:
  // 对标: beforeDestroy
  // 场景: 做清除的动作, 清除定时器/ 解除监听的事件等
  componentWillUnmount() {
    clearInterval(timerId);
    console.log('卸载前被执行了  ----->  ');
  }
}
